import requests
from bs4 import BeautifulSoup

# 目标网页 URL 列表，包含多个品牌和型号的手机页面
urls = [
    'https://www.gsmarena.com/apple_iphone_14-11819.php',
    'https://www.gsmarena.com/samsung_galaxy_s23-11820.php',
    'https://www.gsmarena.com/xiaomi_13-11821.php'
]

# 遍历每个链接并获取上市时间
for url in urls:
    # 发送请求
    response = requests.get(url)
    response.encoding = 'utf-8'  # 设置编码为 utf-8

    # 检查请求是否成功
    if response.status_code == 200:
        # 解析 HTML 内容
        soup = BeautifulSoup(response.text, 'html.parser')

        # 获取发布日期
        try:
            release_date = soup.find('span', {'class': 'released'}).text.strip()
            print(f'{url} 上市时间: {release_date}')
        except AttributeError:
            print(f'{url} 未找到上市时间')

    else:
        print(f'{url} 网页请求失败，状态码: {response.status_code}')
